package com.isorf.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.isorf.mapper.brandmapper;
import com.isorf.mapper.colormapper;
import com.isorf.mapper.shoemapper;
import com.isorf.pojo.color;
import com.isorf.pojo.links;
import com.isorf.pojo.student;
import com.isorf.service.colorservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class colorserviceimpl implements colorservice {

    @Autowired
    private shoemapper shoemapper;
    @Autowired
    private com.isorf.mapper.colormapper colormapper;

    @Override
    public Boolean updatecolor(color color) {

        int result = colormapper.updatecolor(color);
        return result > 0;
    }

    @Override
    public Boolean addcolor(color color) {

        int result = colormapper.addcolor(color);
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public PageInfo<color> pageList(int pageNum, int pageSize) {

        // 使用PageHelper.startPage方法设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        // 查询所有用户数据，此时查询会被自动分页
        List<color> userList = (List<color>) colormapper.pageList();
        // 使用PageInfo包装查询结果，便于页面使用
        return new PageInfo<>(userList);
    }

    @Override
    public Boolean batchDelete(List<Integer> ids) {
        // 先删除shoe表中引用这些color_id的记录
        shoemapper.deleteByColorIds(ids);

        // 再删除color表中的记录
        int result = colormapper.batchDelete(ids);
        return result > 0;
    }

    @Override
    public Boolean deletecolor(Integer colorId) {
        int result = colormapper.deletecolor(colorId);
        return result > 0;
    }
    @Override
    public List<color> getallcolor()
    {
        return colormapper.getallcolor();
    }

}
